#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2018/1/21 0021 14:43
# @Author  : Arliki
# @File    : coroutine_t.py

# 协程实现

import time, asyncio


def consumer():
    r = ''
    while 1:
        n = yield r
        if not n:
            return
        print("consumer get:%s" % n)
        r = "consumer %s is ok" % n


def producer(g):
    g.send(None)
    n = 0
    while n < 11:
        n += 1
        print("producer send %s" % n)
        r = g.send(n)
        print("producer receive %s from consumer" % r)
    g.close()


def run():
    g = consumer()
    producer(g)


def run2():
    a = lambda: time.time()
    b = a()
    coroutine = async_coroutine()
    loop = asyncio.get_event_loop()
    loop.run_until_complete(coroutine)
    print(b)


async def async_coroutine():
    print("async_coroutine")


if __name__ == '__main__':
    run2()
    #   http://python.jobbole.com/87310/
